package com.dianziq.im.server;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
	private Properties prop = new Properties();

	public static final Config INSTANCE = new Config();

	// public String getConfigs(String name) {
	// return prop.getProperty(name);
	// }
	public String get(String name) {
		return this.prop.getProperty(name);
	}

	public int getInt(String name, int defaultValut) {
		return Integer.parseInt(get(name, defaultValut + ""));
	}

	public String get(String name, String defaultValue) {
		String s = this.prop.getProperty(name);
		if (s == null) {
			return defaultValue;
		}
		return s.trim();
	}

	private Config() {
		File f = new File("../conf/main.properties");

		InputStream in = null;
		try {
			in = f.exists() ? new java.io.FileInputStream(f) : Config.class
					.getResourceAsStream("/main.properties");
			try {
				prop.load(in);
			} catch (IOException e) {
				System.err.println("Cannot load config file");
				System.exit(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}